/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apt.Bean;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apt.connectDB.MyConnect;

/**
 *
 * @author MinhThang
 */
public class Bean extends org.apache.struts.action.ActionForm {
    
   private String txtUserName;
   private String txtPassword;
   private String txtFullName;
   private boolean gender;
   private String txtBirthday;
   private int txtIDCard;
   private String txtEmail;
   private int txtMobile;
   private int txtHomePhone;
   private String txtAddress;
   private String fileUpLoad;


    /**
     *
     */
    public Bean() {
        super();
        // TODO Auto-generated constructor stub
    }
    public boolean Register(){

        //Insert data to Member table
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            conn=MyConnect.getConnection();
            String sql="insert  Member ( UserName , Password ,FullName ,Image , Email ,  DOB ,IDCard ,MobilePhone ,HomePhone ,Address ,Status , Description , Gender) values(?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
            ps=conn.prepareCall(sql);
            ps.setString(1, getTxtUserName());
            ps.setString(2, getTxtPassword());
            ps.setString(3, getTxtFullName());
            ps.setString(4, getFileUpLoad());
            ps.setString(5, getTxtEmail());
            ps.setString(6, getTxtBirthday());
            ps.setInt(7, getTxtIDCard());
            ps.setInt(8, getTxtMobile());
            ps.setInt(9, getTxtHomePhone());
            ps.setString(10, getTxtAddress());
            ps.setBoolean(11, isGender());
            ps.setString(12, "");
            ps.setBoolean(13, true);
            ps.executeUpdate();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }




    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getTxtUserName() == null || getTxtUserName().length() < 1) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }else if(getTxtPassword() == null || getTxtPassword().length() < 1){
            errors.add("name", new ActionMessage("error.name.required"));
        }
        return errors;
    }
    

    /**
     * @return the txtUserName
     */
    public String getTxtUserName() {
        return txtUserName;
    }

    /**
     * @param txtUserName the txtUserName to set
     */
    public void setTxtUserName(String txtUserName) {
        this.txtUserName = txtUserName;
    }

    /**
     * @return the txtPassword
     */
    public String getTxtPassword() {
        return txtPassword;
    }

    /**
     * @param txtPassword the txtPassword to set
     */
    public void setTxtPassword(String txtPassword) {
        this.txtPassword = txtPassword;
    }

    /**
     * @return the txtFullName
     */
    public String getTxtFullName() {
        return txtFullName;
    }

    /**
     * @param txtFullName the txtFullName to set
     */
    public void setTxtFullName(String txtFullName) {
        this.txtFullName = txtFullName;
    }

    /**
     * @return the gender
     */
    public boolean isGender() {
        return gender;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(boolean gender) {
        this.gender = gender;
    }

    /**
     * @return the txtBirthday
     */
    public String getTxtBirthday() {
        return txtBirthday;
    }

    /**
     * @param txtBirthday the txtBirthday to set
     */
    public void setTxtBirthday(String txtBirthday) {
        this.txtBirthday = txtBirthday;
    }

    /**
     * @return the txtIDCard
     */
    public int getTxtIDCard() {
        return txtIDCard;
    }

    /**
     * @param txtIDCard the txtIDCard to set
     */
    public void setTxtIDCard(int txtIDCard) {
        this.txtIDCard = txtIDCard;
    }

    /**
     * @return the Email
     */
   

    /**
     * @param Email the Email to set
     */
    

    /**
     * @return the txtMobile
     */
    public int getTxtMobile() {
        return txtMobile;
    }

    /**
     * @param txtMobile the txtMobile to set
     */
    public void setTxtMobile(int txtMobile) {
        this.txtMobile = txtMobile;
    }

    /**
     * @return the txtHomePhone
     */
    public int getTxtHomePhone() {
        return txtHomePhone;
    }

    /**
     * @param txtHomePhone the txtHomePhone to set
     */
    public void setTxtHomePhone(int txtHomePhone) {
        this.txtHomePhone = txtHomePhone;
    }

    /**
     * @return the txtAddress
     */
    public String getTxtAddress() {
        return txtAddress;
    }

    /**
     * @param txtAddress the txtAddress to set
     */
    public void setTxtAddress(String txtAddress) {
        this.txtAddress = txtAddress;
    }

    /**
     * @return the fileUpLoad
     */
    public String getFileUpLoad() {
        return fileUpLoad;
    }

    /**
     * @param fileUpLoad the fileUpLoad to set
     */
    public void setFileUpLoad(String fileUpLoad) {
        this.fileUpLoad = fileUpLoad;
    }

    /**
     * @return the txtEmail
     */
    public String getTxtEmail() {
        return txtEmail;
    }

    /**
     * @param txtEmail the txtEmail to set
     */
    public void setTxtEmail(String txtEmail) {
        this.txtEmail = txtEmail;
    }
}
